package com.polidea.rxohosble2.internal.util;

import com.polidea.rxohosble2.internal.RxBleLog;

import bleshadow.javax.inject.Inject;
import ohos.app.Context;
import ohos.bluetooth.ble.BlePeripheralDevice;
import ohos.bluetooth.ble.BlePeripheralCallback;

public class BleConnectionCompat {

    private final Context context;

    @Inject
    public BleConnectionCompat(Context context) {
        this.context = context;
    }

    public BlePeripheralDevice connectGatt(BlePeripheralDevice remoteDevice, boolean autoConnect, BlePeripheralCallback bluetoothGattCallback) {

        if (remoteDevice == null) {
            return null;
        }
        return connectGattCompat(bluetoothGattCallback, remoteDevice, autoConnect);
    }

    private BlePeripheralDevice connectGattCompat(BlePeripheralCallback bluetoothGattCallback, BlePeripheralDevice device, boolean autoConnect) {
        RxBleLog.v("Connecting without reflection");
        device.connect(autoConnect, bluetoothGattCallback);
        return device;
    }
}
